package model

// 购物车结构体
type Cart struct {
	CartID      string      // 购物车id
	CartItems   []*CartItem // 所有购物项
	TotalCount  int64       // 总数量
	TotalAmount float64     // 总金额
	UserID      int         // 购物车所属用户
}

func (cart *Cart) GetTotalCount() int64 {
	// 遍历购物车中的购物项切片
	var totalCount int64
	for _, v := range cart.CartItems {
		totalCount = totalCount + v.Count
	}
	return totalCount
}
func (cart *Cart) GetTotalAmount() float64 {
	var totalAmount float64
	for _, v := range cart.CartItems {
		totalAmount = totalAmount + v.GetAmount()
	}
	return totalAmount
}
